/**
 * 系统名称: 企业财资
 * 模块名称: repair-boot
 * 类 名 称: Service.java
 * 软件版权: 恒生电子股份有限公司
 * 修改记录:
 * 修改人员:
 * 修改说明:
 * ============ ============================================
 * zhanghong 创建
 * ============ ============================================
 */
package com.mt.repair.utils;

import com.mt.common.core.utils.SpringContextUtils;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

/**
 * @author zhanghong
 * @date 2023-03-17 12:53
 */
//@Component
public class ServiceName {

    public static Map<String,List<String>> serviceMap=new HashMap<>();
    /**
     * @param
     * @return
     * @Author zhanghong
     * @description 获取当前项目下所有的serviceName
     * @date 2023/3/17
     * @methodName
     */
    //public List<String> findAllServices() {
    //    List<String> result = new ArrayList<>();
    //    //spring工具类，可以获取指定路径下的全部类
    //    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    //    try {
    //        String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
    //                ClassUtils.convertClassNameToResourcePath("com.mt.repair") + "/service/**/impl/*.class";
    //        Resource[] resources = resourcePatternResolver.getResources(pattern);
    //        //MetadataReader 的工厂类
    //        MetadataReaderFactory readerfactory = new CachingMetadataReaderFactory(resourcePatternResolver);
    //        for (Resource resource : resources) {
    //            //用于读取类信息
    //            MetadataReader reader = readerfactory.getMetadataReader(resource);
    //            //扫描到的class
    //            String classname = reader.getClassMetadata().getClassName();
    //            Class<?> clazz = Class.forName(classname);
    //            //判断是否有指定主解
    //            Service anno = clazz.getAnnotation(Service.class);
    //            if (anno != null) {
    //                //将注解中的类型值作为key，对应的类作为 value
    //                result.add(classname.substring(classname.lastIndexOf(".") + 1, classname.length()));
    //            }
    //        }
    //        return result;
    //    } catch (ClassNotFoundException | IOException e) {
    //        e.printStackTrace();
    //        return result;
    //    }
    //
    //}
    //
    //public static void main(String[] args) {
    //    ServiceName serviceName = new ServiceName();
    //    List<String> allServices = serviceName.findAllServices();
    //    System.out.println("");
    //
    //}
    //
    //public List<String> findMethods(String beanName) {
    //    String ignore = "dispatch,equals,toString,hashCode,clone,log,indexOf,indexOf,newInstance,newInstance,newInstance,isFrozen,getTargetClass,getAdvisors,removeAdvice,isExposeProxy,replaceAdvisor,removeAdvisor,removeAdvisor,setExposeProxy,setPreFiltered,addAdvice,addAdvice,setTargetSource,getTargetSource,isPreFiltered,addAdvisor,addAdvisor,getProxiedInterfaces,isInterfaceProxied,isProxyTargetClass,toProxyConfigString,getLoginUserId,businessLog,setSavePulicColumns,getCurrentOrganizationId,getCurrentOrganizationName,checkForeignEntity,canDownloadAttachment,getLoginUser,startPage,getUser,getStoreId,setCallback,setCallbacks,getCallbacks,getCallback";
    //    Set<String> ignoreSet = new HashSet<String>(Arrays.asList(ignore.split(",")));
    //    List<String> result = new ArrayList<>();
    //    Object object = SpringContextUtils.getBean(beanName);
    //    String cur = "";
    //    Method[] methods = object.getClass().getDeclaredMethods();
    //    for (int i = 0; i < methods.length; i++) {
    //        if (!ignoreSet.contains(methods[i].getName())&&!methods[i].getName().contains("CGLIB")) {
    //            result.add(methods[i].getName());
    //        }
    //    }
    //    return result;
    //}
    //
    //public void invok() {
    //    Object repairOrderService = SpringContextUtils.getBean("repairOrderServiceBean");
    //    Method[] methods = repairOrderService.getClass().getMethods();
    //    try {
    //        Method findRepairOrder = repairOrderService.getClass().getDeclaredMethod("findRepairOrder", Long.class);
    //        Object invoke = findRepairOrder.invoke(repairOrderService, 30L);
    //        System.out.println(findRepairOrder);
    //    } catch (NoSuchMethodException e) {
    //        e.printStackTrace();
    //    } catch (InvocationTargetException e) {
    //        e.printStackTrace();
    //    } catch (IllegalAccessException e) {
    //        e.printStackTrace();
    //    }
    //}
    public static void main(String[] args) throws SchedulerException {

    }
}
